﻿/**  版本信息模板在安装目录下，可自行修改。
* object_category.cs
*
* 功 能： N/A
* 类 名： object_category
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/1/2 22:18:53   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using ZGEDrySaltery.IDAL;
using Maticsoft.DBUtility;//Please add references
namespace ZGEDrySaltery.MySQLDAL
{
	/// <summary>
	/// 数据访问类:object_category
	/// </summary>
	public partial class object_category:Iobject_category
	{
		public object_category()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("PCID", "object_category"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int PCID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from object_category");
			strSql.Append(" where PCID=@PCID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@PCID", MySqlDbType.Int32,11)			};
			parameters[0].Value = PCID;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ZGEDrySaltery.Model.object_category model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into object_category(");
			strSql.Append("PCID,NAME,PINYIN,ALIAS,PREPCID,SORT,INSERTTIME,MODIFYTIME)");
			strSql.Append(" values (");
			strSql.Append("@PCID,@NAME,@PINYIN,@ALIAS,@PREPCID,@SORT,@INSERTTIME,@MODIFYTIME)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@PCID", MySqlDbType.Int32,11),
					new MySqlParameter("@NAME", MySqlDbType.VarChar,32),
					new MySqlParameter("@PINYIN", MySqlDbType.VarChar,32),
					new MySqlParameter("@ALIAS", MySqlDbType.VarChar,32),
					new MySqlParameter("@PREPCID", MySqlDbType.Int32,11),
					new MySqlParameter("@SORT", MySqlDbType.Int32,11),
					new MySqlParameter("@INSERTTIME", MySqlDbType.DateTime),
					new MySqlParameter("@MODIFYTIME", MySqlDbType.DateTime)};
			parameters[0].Value = model.PCID;
			parameters[1].Value = model.NAME;
			parameters[2].Value = model.PINYIN;
			parameters[3].Value = model.ALIAS;
			parameters[4].Value = model.PREPCID;
			parameters[5].Value = model.SORT;
			parameters[6].Value = model.INSERTTIME;
			parameters[7].Value = model.MODIFYTIME;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZGEDrySaltery.Model.object_category model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update object_category set ");
			strSql.Append("NAME=@NAME,");
			strSql.Append("PINYIN=@PINYIN,");
			strSql.Append("ALIAS=@ALIAS,");
			strSql.Append("PREPCID=@PREPCID,");
			strSql.Append("SORT=@SORT,");
			strSql.Append("INSERTTIME=@INSERTTIME,");
			strSql.Append("MODIFYTIME=@MODIFYTIME");
			strSql.Append(" where PCID=@PCID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@NAME", MySqlDbType.VarChar,32),
					new MySqlParameter("@PINYIN", MySqlDbType.VarChar,32),
					new MySqlParameter("@ALIAS", MySqlDbType.VarChar,32),
					new MySqlParameter("@PREPCID", MySqlDbType.Int32,11),
					new MySqlParameter("@SORT", MySqlDbType.Int32,11),
					new MySqlParameter("@INSERTTIME", MySqlDbType.DateTime),
					new MySqlParameter("@MODIFYTIME", MySqlDbType.DateTime),
					new MySqlParameter("@PCID", MySqlDbType.Int32,11)};
			parameters[0].Value = model.NAME;
			parameters[1].Value = model.PINYIN;
			parameters[2].Value = model.ALIAS;
			parameters[3].Value = model.PREPCID;
			parameters[4].Value = model.SORT;
			parameters[5].Value = model.INSERTTIME;
			parameters[6].Value = model.MODIFYTIME;
			parameters[7].Value = model.PCID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int PCID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from object_category ");
			strSql.Append(" where PCID=@PCID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@PCID", MySqlDbType.Int32,11)			};
			parameters[0].Value = PCID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string PCIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from object_category ");
			strSql.Append(" where PCID in ("+PCIDlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZGEDrySaltery.Model.object_category GetModel(int PCID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PCID,NAME,PINYIN,ALIAS,PREPCID,SORT,INSERTTIME,MODIFYTIME from object_category ");
			strSql.Append(" where PCID=@PCID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@PCID", MySqlDbType.Int32,11)			};
			parameters[0].Value = PCID;

			ZGEDrySaltery.Model.object_category model=new ZGEDrySaltery.Model.object_category();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZGEDrySaltery.Model.object_category DataRowToModel(DataRow row)
		{
			ZGEDrySaltery.Model.object_category model=new ZGEDrySaltery.Model.object_category();
			if (row != null)
			{
				if(row["PCID"]!=null && row["PCID"].ToString()!="")
				{
					model.PCID=int.Parse(row["PCID"].ToString());
				}
				if(row["NAME"]!=null)
				{
					model.NAME=row["NAME"].ToString();
				}
				if(row["PINYIN"]!=null)
				{
					model.PINYIN=row["PINYIN"].ToString();
				}
				if(row["ALIAS"]!=null)
				{
					model.ALIAS=row["ALIAS"].ToString();
				}
				if(row["PREPCID"]!=null && row["PREPCID"].ToString()!="")
				{
					model.PREPCID=int.Parse(row["PREPCID"].ToString());
				}
				if(row["SORT"]!=null && row["SORT"].ToString()!="")
				{
					model.SORT=int.Parse(row["SORT"].ToString());
				}
				if(row["INSERTTIME"]!=null && row["INSERTTIME"].ToString()!="")
				{
					model.INSERTTIME=DateTime.Parse(row["INSERTTIME"].ToString());
				}
				if(row["MODIFYTIME"]!=null && row["MODIFYTIME"].ToString()!="")
				{
					model.MODIFYTIME=DateTime.Parse(row["MODIFYTIME"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PCID,NAME,PINYIN,ALIAS,PREPCID,SORT,INSERTTIME,MODIFYTIME ");
			strSql.Append(" FROM object_category ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM object_category ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.PCID desc");
			}
			strSql.Append(")AS Row, T.*  from object_category T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "object_category";
			parameters[1].Value = "PCID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

